package com.se.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.pulp.model.JQGridRow;
import com.pulp.service.OrgnizationInfoService;

public class Go1Action<UserInfoVO> extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(Go1Action.class);

	private String errorCode = "";
	private String page;
	private String total;
	private List rows;

	private List myList = null;

	

	public String excute() throws Exception {

		try {

			HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			OrgnizationInfoService orgnizationInfoService = (OrgnizationInfoService) wac.getBean("orgnizationInfoService");
			myList = (List) orgnizationInfoService.getUserInfo();

			// List loginList = orgnizationInfoService.getUserInfo();

		} catch (Exception ex) {
			REQUEST_RESULT = "FAILED";
			ex.printStackTrace();
		}
		return REQUEST_RESULT;
	}

	@SuppressWarnings("unchecked")
	public String userList() throws Exception {

		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

		ServletContext servletContext = ServletActionContext.getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
		OrgnizationInfoService orgnizationInfoService = (OrgnizationInfoService) wac.getBean("orgnizationInfoService");

		List result1 = (List) orgnizationInfoService.getUserInfo();

		// System.out.println("result1=====   " + result1.get(0));

		page = "1";
		total = String.valueOf(result1.size());

		rows = new ArrayList<JQGridRow>();

		for (int idx = 0; idx < result1.size(); idx++) {
			Map result = (Map) result1.get(idx);

			// System.out.println("aaaaaa====" + (Map)result1.get(idx));

			JQGridRow jQGridRow = new JQGridRow();
			jQGridRow.setId(idx + 1);
			ArrayList cells = new ArrayList();

			for (int j = 0; j < 16; j++) {

				// if (j == 0 && idx == 0){
				// cells.add("평택");
				// }else if (j == 0 && idx == 1){
				// cells.add("천안");
				// }else if (j == 0 && idx == 2){
				// cells.add("함안");
				// }else if (j == 1){
				// cells.add(result.get("EMPID"));
				// }else if ( j == 2){
				// cells.add(result.get("JOBID"));
				// }else if ( j == 3){
				// cells.add(result.get("COUNTRYID"));
				// }else if ( j == 4){
				// cells.add(result.get("FIRSTNM"));
				// }else if ( j == 5){
				// cells.add(result.get("SALARY"));
				// }else if ( j == 6){
				// cells.add(result.get("CITY"));
				// }

				if (j == 0) {
					cells.add(result.get("TOTAL"));
				} else if (j == 1) {
					cells.add(result.get("A1"));
				} else if (j == 2) {
					cells.add(result.get("A2"));
				} else if (j == 3) {
					cells.add(result.get("A3"));
				} else if (j == 4) {
					cells.add(result.get("A4"));
				} else if (j == 5) {
					cells.add(result.get("A5"));
				} else if (j == 6) {
					cells.add(result.get("A6"));
				} else if (j == 7) {
					cells.add(result.get("A7"));
				} else if (j == 8) {
					cells.add(result.get("A8"));
				} else if (j == 9) {
					cells.add(result.get("A9"));
				} else if (j == 10) {
					cells.add(result.get("A10"));
				} else if (j == 11) {
					cells.add(result.get("A11"));
				} else if (j == 12) {
					cells.add(result.get("A12"));
				} else if (j == 13) {
					cells.add(result.get("A13"));
				} else if (j == 14) {
					cells.add(result.get("A14"));
				} else if (j == 15) {
					cells.add(result.get("A15"));
				}

			}

			jQGridRow.setCell(cells);
			rows.add(jQGridRow);
		}

		return Action.SUCCESS;
	}
	
	public List getMyList() {
		return myList;
	}

	public void setMyList(List myList) {
		this.myList = myList;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getTotal() {
		return total;
	}

	public void setTotal(String total) {
		this.total = total;
	}

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}

	public Go1Action() {}

}